import store from '~/store'

export default {
  install(app){
    app.directive('permission',{
      mounted(el, binding) {
        // el - dom节点对象
        // binding.value - 自定义指令应用于组件时传递的参数
        hasPermission(binding.value,el)
      },
    })
  }
}

function hasPermission(value, el=false){
  if(!Array.isArray(value))
    throw new Error(`需要设定权限：v-permission='["getState,GET"]'`)
  const userInfo = store.state.user.sysUser
  if(userInfo.iid !== 2 && el)
    el.parentNode && el.parentNode.removeChild(el)
}